package com.example;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Author: wyp
 * @Date: 2021/9/15 17:54
 * Executor创建线程池Demo
 */
public class ExecutorDemo {
    public static void main(String[] args) throws InterruptedException {
        //核酸检测窗口 20个
        //ExecutorService executorService = Executors.newFixedThreadPool(20);
        //核酸检测窗口 1个
        //ExecutorService executorService = Executors.newSingleThreadExecutor();
        //核酸检测窗口 随机 人多就开窗口，人少就少开窗口
        ExecutorService executorService = Executors.newCachedThreadPool();


        try {
            //表示200个人
            for (int i = 0; i < 200; i++) {
                executorService.submit(()->{
                    System.out.println(Thread.currentThread().getName()+"\t 窗口正在做核酸。。。");
                });
            }

            Thread.sleep(5000);
        }finally {
            executorService.shutdown();
            System.out.println("核酸检测完成，关闭核酸检测点。");
        }
    }
}
